﻿import store from './store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { Notification, MessageBox, Message, Loading } from 'element-ui'
import router from './router'
import {
    getToken
} from '@/utils/auth'

router.beforeEach((to, from, next) => {
    NProgress.start()
    if (getToken()) {
        if (to.path === '/login') {
            next({
                path: '/'
            })
            NProgress.done()
        }else {
            // 判断当前用户是否已拉取完user_info信息
            store.dispatch('GetInfo').then(() => {

            }).catch(err => {
                store.dispatch('LogOut').then(() => {
                    next({
                        path: '/'
                    })
                })
            })
        }
    } else {


    }
    //console.log(to)
    //console.log(from)
    next()


})

router.afterEach(() => {
    NProgress.done()
})
